//
//  QDLoginModel.m
//  simulateQuickDoctor
//
//  Created by 胡卓 on 2017/3/25.
//  Copyright © 2017年 PipiXia. All rights reserved.
//

#import "QDLoginModel.h"

@implementation QDLoginModel

- (void)setValue:(id)value forUndefinedKey:(NSString *)key{}

- (NSString *)description{
    return [NSString stringWithFormat:@"姓名: %@, 年龄: %@, 性别: %@, 身高: %@, 体重: %@, 籍贯: %@, 联系方式: %@, 证件号码: %@,,常居地: %@",_true_name,_age,_gender,_height,_weight,_address,_mobile_number,_card_number,_residence];
}

+ (instancetype)loginWithDict:(NSDictionary *)dict {
    
    QDLoginModel *model = [[QDLoginModel alloc]init];
    
    [model setValuesForKeysWithDictionary:dict];
    
    //初始化性别和长居地
    model.gender = @"女";
    model.residence = @"斯里兰卡";
    
    return model;
}


#pragma mark -   归档解档

//归档，将对象的属性保存起来
- (void)encodeWithCoder:(NSCoder *)aCoder {
    
    //类型不同，数据归档不同
    [aCoder encodeObject:_true_name forKey:@"true_name"];
    [aCoder encodeObject:_age forKey:@"age"];
    [aCoder encodeObject:_gender forKey:@"gender"];
    [aCoder encodeObject:_height forKey:@"height"];
    [aCoder encodeObject:_weight forKey:@"weight"];
    [aCoder encodeObject:_address forKey:@"address"];
    [aCoder encodeObject:_residence forKey:@"residence"];
    [aCoder encodeObject:_mobile_number forKey:@"mobile_number"];
    [aCoder encodeObject:_card_number forKey:@"card_number"];
    [aCoder encodeObject:_head_photo forKey:@"head_photo"];
}




//解档
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder {
    
    if (self = [super init]) {
        
        //将解档出来的数据赋值给原来的数据上
        _true_name = [aDecoder decodeObjectForKey:@"true_name"];
        _age = [aDecoder decodeObjectForKey:@"age"];
        _gender = [aDecoder decodeObjectForKey:@"gender"];
        _height = [aDecoder decodeObjectForKey:@"height"];
        _weight = [aDecoder decodeObjectForKey:@"weight"];
        _address = [aDecoder decodeObjectForKey:@"address"];
        _residence = [aDecoder decodeObjectForKey:@"residence"];
        _mobile_number = [aDecoder decodeObjectForKey:@"mobile_number"];
        _card_number = [aDecoder decodeObjectForKey:@"card_number"];
        _head_photo = [aDecoder decodeObjectForKey:@"head_photo"];
    }
    return self;
}
@end
